import logging
from time import sleep

import requests

from main.config import headers


def download_img(img_url):
    response = requests.get(img_url, stream=True, headers=headers)
    if(response.status_code == 200):
        logging.info('{} 下载成功'.format(img_url))
        return response.content
    else:
        logging.info("{} 请求失败".format(img_url))


def download_imgs(img_url_list):
    result = []
    for img_url in img_url_list:
        img = download_img(img_url)
        if img is not None:
            result.append(img)
            sleep(0.5)

    return result
